package Q485

/**
 * 最大连续1的个数
 * @author 23737
 * @date 2022.5.12
 */
fun main() {
    val nums = intArrayOf(1,0,1,1,0,1)
    println(Solution().findMaxConsecutiveOnes(nums))
}

class Solution {
    fun findMaxConsecutiveOnes(nums: IntArray): Int {
        var max = 0
        var res = 0
        if (nums.isEmpty()) return max
        for (i in nums.indices) {
            if (nums[i] == 1) {
                res += 1
            } else {
                max = Math.max(max, res)
                res = 0
            }
        }
        return Math.max(max, res)
    }
}